package com.xiaomai.server;

import java.util.Map;
import java.util.Set;
import java.util.UUID;


import com.xiaomai.Dao.Address;
import com.xiaomai.entity.AddressEntity;
import com.xiaomai.entity.Cart;
import com.xiaomai.entity.Cartltem;
import com.xiaomai.entity.DD_Order_Pro;
import com.xiaomai.entity.Location;
import com.xiaomai.entity.UserEntity;

import MyUtil.MyUitl;


public class AddressServiceImpl implements AddressService{

	public void address(UserEntity user, AddressEntity add, Cart cart) {
		// TODO Auto-generated method stub
		Address mapper = (Address) MyUitl.getMapper(Address.class);
		
		add.setId(UUID.randomUUID().toString());
		add.setUser_id(user);
		
		Location location=new Location();
		location.setId(UUID.randomUUID().toString());
		location.setUser_id(user);
		
		DD_Order_Pro dd=new DD_Order_Pro();
		//用cart get  map出来
		Map<String, Cartltem> map = cart.getMap();
		//然后用map.key出来
		Set<String> keySet = map.keySet();
		for (String string : keySet) {
			dd.setId(UUID.randomUUID().toString());
			dd.setLocation(location);
			dd.setAmount(map.get(string).getAmount());
			dd.setDang_price(map.get(string).getPrice());
			dd.setProduct_id(map.get(string).getBook());
			location.setTotal(location.getTotal()+dd.getDang_price());
			
		}
		//掉用dao的方法
		System.out.println(user);
		System.out.println(location);
		System.out.println(dd);
		location.setAddress_id(add);
		mapper.address(add);
		mapper.order(location);
		mapper.Order_items(dd);
		
	}
}



